﻿// demo.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include <iostream>
#include <string>
#include <windows.h>
#include "VmControlInf.h"

using namespace std;

int main()
{
	string cmd;

	printf("usage: \n");
	printf("h  show usage\n");
	printf("o  open device first\n");
	printf("n  insert new monitor\n");
	printf("d  depart monitor\n");
	printf("v  query driver version\n");
	printf("s  detect you system is supported or not\n");
	printf("e  echo test\n");
	printf("E  Enable  driver\n");
	printf("D  Disable driver\n");
	printf("i  install driver\n");
	printf("u  uninstall driver\n");
	printf("x  extend monitor\n");
	printf("c  clone monitor\n");
	printf("r  internal monitor\n");
	printf("p  change disp\n");
	printf("a  auto test\n");
	printf("f  auto insert/remove\n");
	printf("k  check display mode\n");
	printf("q  quit test\n");

	while (true) {
		cin >> cmd;
		if (cmd == "o") {
			if (BJOpenVM())
				printf("BJOpenVM Succeeded!\n");
			else
				printf("BJOpenVM Failed!\n");
		}
		else if (cmd == "n") {
			if (BJNewMonitor())
				printf("NewMonitorTest Succeeded!\n");
			else
				printf("NewMonitorTest Failed!\n");
		}
		else if (cmd == "d") {
			if (BJDelMonitor())
				printf("DelMonitorTest Succeeded!\n");
			else
				printf("DelMonitorTest Failed!\n");
		}
		else if (cmd == "v") {
			printf("driver version: %s \n", BJQueryDriverVersion());
		}
		else if (cmd == "s") {
			if (BJDetectIsOsSupported()) {
				printf("You system is supported\n");
			}
			else {
				printf("You system is not supported\n");
			}
		}
		else if (cmd == "e") {
			if (BJEchoTest())
				printf("Call IOCTL Succeeded!\n");
			else
				printf("Call IOCTL Failed!\n");
		}
		else if (cmd == "E") {
			printf("Enable driver :%d\n", BJEnableDrv());
		}
		else if (cmd == "D") {
			printf("Disable driver: %d\n", BJDisableDrv());
		}
		else if (cmd == "i") {
			printf("install driver: %d\n", BJInstallDrv());
		}
		else if (cmd == "u") {
			printf("uninstall driver: %d\n", BJUnInstallDrv());
		}
		else if (cmd == "x") {
			printf("extend monitor: %d\n", BJForceExtendMonitor());
		}
		else if (cmd == "c") {
			printf("clone monitor: %d\n", BJForceCloneMonitor());
		}
		else if (cmd == "r") {
			printf("clone monitor: %d\n", BJForceRestoreMonitor());
		}
		else if (cmd == "p") {
			printf("change disp: %d\n", BJForceChangeDisp(1920,1080));
		}
		else if (cmd == "f") {
			printf("start auto insert remove now\n");
			int cnt = 9600;
			while (cnt--)
			{
				printf("TEST ADD times: %d\n", cnt);
				if (!BJNewMonitor()) {
					printf("NewMonitorTest Failed!\n");
					BJCloseVM();
					break;
				}
				Sleep(3000);
				printf("TEST DEL times: %d\n", cnt);
				if (!BJDelMonitor()) {
					printf("DelMonitorTest Failed!\n");
					BJCloseVM();
					break;
				}
				Sleep(3000);

				printf("\n");
			}
		}
		else if (cmd == "t") {
			printf("start auto test...now %d\n");
			while (true)
			{
				printf("TEST ECHO\n");
				if (!BJEchoTest()) {
					printf("Call IOCTL Failed!\n");
				}
				Sleep(2000);
				printf("TEST NEW\n");
				if (!BJNewMonitor()) {
					printf("NewMonitorTest Failed!\n");
					return 0;
				}
				Sleep(2000);
				printf("TEST EXTENDMONITOR\n");
				BJForceExtendMonitor();
				Sleep(2000);
				printf("TEST RESTOREMONITOR\n");
				BJForceRestoreMonitor();
				Sleep(2000);
				printf("TEST DEL\n");
				if (!BJDelMonitor()) {
					printf("DelMonitorTest Failed!\n");
					return 0;
				}
			}
		}
		else if (cmd == "q") {
			BJCloseVM();
			break;
		}
		else if (cmd == "k") {
			printf("check monitor display mode: %d\n", static_cast<int>(BJCheckDisplayMode()));
		}
		else {
			printf("h  show usage\n");
			printf("n  insert new monitor\n");
			printf("d  depart monitor\n");
			printf("v  query driver version\n");
			printf("s  detect you system is supported or not\n");
			printf("e  echo test\n");
			printf("E  Enable  driver\n");
			printf("D  Disable driver\n");
			printf("i  install driver\n");
			printf("u  uninstall driver\n");
			printf("x  extend monitor\n");
			printf("c  clone monitor\n");
			printf("r  internal monitor\n");
			printf("p  change disp\n");
			printf("a  auto test\n");
			printf("f  auto insert/remove\n");
			printf("k  check display mode\n");
			printf("q  quit test\n");
		}
	}

	return 0;
}

